package com.example.myapplication13;

import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        EditText number=(EditText) findViewById(R.id.edit_text1);
        EditText password=(EditText) findViewById(R.id.edit_text2);
        Button button1=(Button) findViewById(R.id.button_1);
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String s1=number.getText().toString();
                String s2=password.getText().toString();
                if(s1.equals("admin")&&s2.equals("admin")){
                    Intent intent=new Intent(MainActivity.this,LoginActivity.class);
                    intent.putExtra("account",s1);
                    intent.putExtra("password",s2);
                    startActivity(intent);
                }
                else{
                    AlertDialog.Builder dialog=new AlertDialog.Builder(MainActivity.this);
                    dialog.setTitle("登录失败");
                    dialog.setMessage("用户名或密码错误");
                    dialog.setCancelable(false);
                    dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {

                        }
                    });
                    dialog.show();
                }
            }

        });
    }
}